import Vue from 'vue';
import VueRouter from 'vue-router';
import index from '../views/index.vue'; //首页
import home from '../views/device-home/index.vue';

import Login from '../views/Login/Login.vue'; //登录页面

import MaterialManagement from '@/views/materialmanagement/Material.vue'; //物料管理

import OperationManage from '@/views/operation-manage/index.vue'; //工序管理

import RouteManage from '@/views/route-manage/index.vue'; //工艺管理

import BasicType from '@/views/basic-type/index.vue'; //基础数据

import PackingPlanMange from '@/views/packingplan-mange/index.vue'; //灌包工单管理

import PackingPlanLMange from '@/views/packingplanL-manage/index.vue'; //灌包工单查看

import Examine from '@/views/examine/index.vue'; //审批管理

import ProSegmentType from '@/views/pro-segment-type/index.vue'; //设备类型

import ProSegment from '@/views/pro-segment/index.vue'; //基础设备

import PrintIndex from '@/views/printIndex/print-index.vue';

Vue.use (VueRouter);
const originalPush = VueRouter.prototype.push;
// 修改 原型对象中的push方法
VueRouter.prototype.push = function push (location) {
  return originalPush.call (this, location).catch (err => err);
};
const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      title: '登录',
    },
  },
  {
    path: '/printIndex',
    name: 'printIndex',
    component: PrintIndex,
    meta: {
      title: '打印页',
    },
  },
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/page',
    name: 'page',
    component: index,
    children: [
      {
        path: '/home',
        name: 'home',
        component: home,
        meta: {
          title: '首页',
        },
      },
      {
        path: '/ProSegmentType',
        component: ProSegmentType,
        name: 'ProSegmentType',
        meta: {
          title: '设备类型',
          keepAlive: true,
        },
      },
      {
        path: '/ProSegment',
        component: ProSegment,
        name: 'ProSegment',
        meta: {
          title: '基础设备',
          keepAlive: true,
        },
      },
      {
        path: '/BasicType',
        component: BasicType,
        name: 'BasicType',
        meta: {
          title: '基础数据',
          keepAlive: true,
        },
      },
      {
        path: '/MaterialManagement',
        component: MaterialManagement,
        name: 'MaterialManagement',
        meta: {
          title: '物料管理',
          keepAlive: true,
        },
      },
      {
        path: '/Examine',
        component: Examine,
        name: 'Examine',
        meta: {
          title: '审批管理',
          keepAlive: true,
        },
      },
      {
        path: '/PackingPlanMange',
        component: PackingPlanMange,
        name: 'PackingPlanMange',
        meta: {
          title: '灌包工单管理',
          keepAlive: true,
        },
      },
      {
        path: '/PackingPlanLMange',
        component: PackingPlanLMange,
        name: 'PackingPlanLMange',
        meta: {
          title: '灌包工单查看',
          keepAlive: true,
        },
      },

      {
        path: '/RouteManage',
        component: RouteManage,
        name: 'RouteManage',
        meta: {
          title: '工艺管理',
          keepAlive: true,
        },
      },
      {
        path: '/OperationManage',
        component: OperationManage,
        name: 'OperationManage',
        meta: {
          title: '工序管理',
          keepAlive: true,
        },
      },
      {
        path: '/BasicType',
        component: BasicType,
        name: 'BasicType',
        meta: {
          title: '基础信息管理',
          keepAlive: true,
        },
      },
      {
        path: '/WorkTemplate',
        component: () => import ('@/views/work-template/index.vue'),
        name: 'WorkTemplate',
        meta: {
          title: '工作模板',
          keepAlive: true,
        },
      },
      {
        path: '/BatchExamine',
        component: () => import ('@/views/batch-examine/index.vue'),
        name: 'BatchExamine',
        meta: {
          title: '批记录审批',
          keepAlive: true,
        },
      },
      {
        path: '/BatchPrint',
        component: () => import ('@/views/batch-printing/index.vue'),
        name: 'BatchPrint',
        meta: {
          title: '批记录详情',
          keepAlive: true,
        },
      },
      {
        path: '/ViewDisinfectionJobRecord',
        component: () =>
          import ('@/views/view-disinfection-jobRecord/index.vue'),
        name: 'ViewDisinfectionJobRecord',
        meta: {
          title: '查看消毒批记录',
          keepAlive: true,
        },
      },
      {
        path: '/AuditDisinfectionJobRecord',
        component: () =>
          import ('@/views/audit-disinfection-jobRecord/index.vue'),
        name: 'AuditDisinfectionJobRecord',
        meta: {
          title: '消毒批记录审批',
          keepAlive: true,
        },
      },
      {
        path: '/DataSourceSetup',
        component: () => import ('@/views/data-source'),
        name: 'DataSourceSetup',
        meta: {
          title: '数据源管理',
          keepAlive: true,
        },
      },
      {
        path: '/ConfigInformation',
        component: () => import ('@/views/config-information/index.vue'),
        name: 'ConfigInformation',
        meta: {
          title: '配置信息',
          keepAlive: true,
        },
      },
      {
        path: '/report/:param1',
        component: () => import ('@/views/report-link/ReportService.vue'),
        name: 'report',
        meta: {
          title: '报表',
          keepAlive: true,
        },
      },
      {
        path: '/AuditTrail',
        component: () => import ('@/views/audit-trail/index.vue'),
        name: 'AuditTrail',
        meta: {
          title: '审计追踪',
          keepAlive: true,
        },
      },
      {
        path: '/ViewQCJobRecord',
        component: () => import ('@/views/batch-printing/qcindex.vue'),
        name: 'ViewQCJobRecord',
        meta: {
          title: '查看质量批记录',
          keepAlive: true,
        },
      },
      {
        path: '/AuditQCJobRecord',
        component: () => import ('@/views/batch-examine/qcindex.vue'),
        name: 'AuditQCJobRecord',
        meta: {
          title: '质量批记录审批',
          keepAlive: true,
        },
      },
      {
        path: '/AuditTotalJobRecord',
        component: () => import ('@/views/batch-examine/totalIndex.vue'),
        name: 'AuditTotalJobRecord',
        meta: {
          title: '批记录汇总审批',
          keepAlive: true,
        },
      },
      {
        path: '/PreDistributionEssence',
        component: () =>
          import ('@/views/essence-liquid-pre-distribution/index.vue'),
        name: 'PreDistributionEssence',
        meta: {
          title: '精华液预分配',
          keepAlive: true,
        },
      },
      {
        path: '/PreStockEssence',
        component: () => import ('@/views/pre-stock-essence/index.vue'),
        name: 'PreStockEssence',
        meta: {
          title: '精华液库存',
          keepAlive: true,
        },
      },
      {
        path: '/InventoryManagement',
        component: () => import ('@/views/InventoryManagement/index.vue'),
        name: 'InventoryManagement',
        meta: {
          title: '精华液盘点',
          keepAlive: true,
        },
      },
      {
        path: '/ExternalDevice',
        component: () =>
          import ('@/views/external-device-management/index.vue'),
        name: 'ExternalDevice',
        meta: {
          title: '外设管理',
          keepAlive: true,
        },
      },
      {
        path: '/Formula',
        component: () =>
          import ('@/views/formula/index.vue'),
        name: 'Formula',
        meta: {
          title: '配方管理',
          keepAlive: true,
        },
      },
    ],
  },
];

const router = new VueRouter ({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach ((to, form, next) => {
  const token = JSON.parse (localStorage.getItem ('nbcToken'));
  if (token) {
    if (to.path == '/login') {
      next ('/home');
    } else {
      next ();
    }
  } else {
    if (to.path == '/login') {
      next ();
    } else {
      next ('/login');
    }
  }
});
export default router;
